package datastruct;

public class Relation {
	private Index pkIndex;
	private Index fkIndex;
	private int relType;
	private int cardinality;
	private String relName;
	
	public static final int REL_NOTHING = 0;
	public static final int REL_JUSTRELATION = 2;
	public static final int REL_UPDATECASCADE = 256;
	public static final int REL_DELETECASCADE = 4096;
	public static final int REL_FULLRELATION = 4352;
	
	public static final int REL_0TON=0;
	public static final int REL_1TON=1;
	public static final int REL_1TO1=2;
	public static final int REL_NTON=3;
	
	public Relation(Index pkIndex, Index fkIndex)
	{
		super();
		this.relType=0;
		this.relName="REL_" + pkIndex.getName() + "_" + fkIndex.getName();
		this.pkIndex=pkIndex;
		this.fkIndex=fkIndex;
	}
	
	public Relation(int relationType, int cardinality, String name, Index pkIndex, Index fkIndex)
	{
		super();
		this.relType=relationType;
		this.cardinality=cardinality;
		this.relName=name;
		this.pkIndex=pkIndex;
		this.fkIndex=fkIndex;
	}
	
	public Index getPkIndex()
	{
		return this.pkIndex;
	}
	
	public Index getFkIndex()
	{
		return this.fkIndex;
	}
	
	public void setPkIndex(Index index)
	{
		this.pkIndex=index;
	}
	
	public void setFkIndex(Index index)
	{
		this.fkIndex=index;
	}
	
	@Override
	public String toString()
	{
		String result="";
		result = result + "PRIMARY KEY: " + pkIndex.toString() + "\n";
		result = result + "FOREIGN KEY: " + fkIndex.toString();
		return result;
	}

	public void setRelType(int relType) {
		this.relType = relType;
	}

	public int getRelType() {
		return relType;
	}

	public void setName(String relName) {
		this.relName = relName;
	}

	public String getName() {
		return relName;
	}
	
	public void setCardinality(int cardinality)
	{
		this.cardinality=cardinality;
	}
	
	public int getCardinality()
	{
		return this.cardinality;
	}
}
